<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/navigationRight.jsp" %>
<%@include file="/WEB-INF/jsp/common/head.jsp" %>
<%@include file="/WEB-INF/jsp/common/navigationLeft.jsp" %>




<style>
    .m2-manageResult-item td{
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px;
    }
    .m2-manageResult-head th{
        white-space: nowrap;
    }
</style>
<div class="m2-userPrizerecord-con">
    <div class="m2-userPrizerecord-head">
        <h3><i></i>我的奖励金记录</h3>
        <a href="#" style="display: none;"></a>
    </div>

    <div class="m2-userCentermanage-accNum">
        <div class="m2-userCentermanage-accNumlef">
            <p class="m2-userCentermanage-accNumtit">
                <span>激活奖励金（元）</span>
                <b class="m2-userCentermanagedraw-moreDetail">
                    <u style="top:-10px;line-height:26px;">
                        <em style="top:8px" class="m2-draw-arr"></em>
                        <em style="top:8px" class="m2-draw-arrBg"></em>
                        奖励金激活部分，投资即可使用
                    </u>
                </b>
            </p>
            <p class="m2-userCentermanage-accNum-leave">0.00</p>
        </div>
        <div class="m2-userCentermanage-accNumrig">
            <p class="m2-userCentermanage-accNumtit">
                <span>待激活奖励金（元）</span>
                <b class="m2-userCentermanagedraw-moreDetail">
                    <u>
                        <em class="m2-draw-arr"></em>
                        <em class="m2-draw-arrBg"></em>
                        奖励金待激活部分，元老会成员专享，项目结清时即可激活
                    </u>
                </b>
            </p>
            <p class="m2-userCentermanage-accNum-return">0.00</p>
        </div>
    </div>

    <div class="m2-manage-search">
        <div class="m2-manage-search-head">
            <h3><i></i>奖励金流水记录</h3>
        </div>


        <div class="m2-manage-search-selector">
            <ul class="m2-manageSearchsel-time">
                <li>时间范围：</li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-sel" data-days='0'>全部</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" data-days='7'>最近7天</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" data-days='30'>一个月</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" data-days='90'>三个月</span></li>
                <li>从<input id="m2-manSeadate-start" type="text"></li>
                <li>到<input id="m2-manSeadate-end" type="text"></li>
            </ul>
            <ul class="m2-manageSearchsel-type">
                <li>资金类型：</li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-sel" data-status="3">全部</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" data-status="1">未激活</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" data-status="2">已激活</span></li>
            </ul>

            <table class="m2-manageResult" cellpadding="0" cellspacing="0">
                <tr class="m2-manageResult-head">
                    <th style="width:120px;">时间</th>
                    <th style="width:155px;">资金类型</th>
                    <th style="width:135px;">描述</th>
                    <th style="width:120px;">金额(元)</th>
                    <th style="width:100px;">激活余额(元)</th>
                    <th style="width:110px;">待激活余额(元)</th>
                </tr>


                <tr class="m2-manageResult-sum">
                    <td colspan="3"></td>
                    <td>总计:<span class="m2-manageResult-total" id='sum_reward'>0.00</span></td>
                    <td></td>
                    <td><span class="m2-manageResult-more">加载更多</span></td>
                </tr>
            </table>
        </div>
    </div>


</div>

</div>
<script type="text/javascript">

    var start = 1;
    var status = 3;
    var time1 = '';
    var time2 = '';
    var pages = 3;
    var days = 0;

    $(document).ready(function(){
        //加载初始数据
        getRewordRecord();
        //加载日历
        ucDatepicker('#m2-manSeadate-start','usercenter-rewardcontrol-getRewardLogAjax',getSearchData,processData);
        ucDatepicker('#m2-manSeadate-end','usercenter-rewardcontrol-getRewardLogAjax',getSearchData,processData);
        //时间过滤按钮
        $('.m2-manageSearchsel-time span').click(function(){
            $('#m2-manSeadate-start').val('');
            $('#m2-manSeadate-end').val('');
            time1 = '';
            time2 = '';
            days = $(this).data('days');
            clear();
            getRewordRecord();
            $('.m2-manageSearchsel-time span.m2-manSealink-sel').addClass('m2-manSealink-unsel');
            $('.m2-manageSearchsel-time span.m2-manSealink-sel').removeClass('m2-manSealink-sel');
            $(this).removeClass('m2-manSealink-unsel');
            $(this).addClass('m2-manSealink-sel');
        });
        //状态过滤按钮
        $('.m2-manageSearchsel-type span').click(function(){
            status = $(this).data('status');
            clear();
            getRewordRecord();
            $('.m2-manageSearchsel-type span.m2-manSealink-sel').addClass('m2-manSealink-unsel');
            $('.m2-manageSearchsel-type span.m2-manSealink-sel').removeClass('m2-manSealink-sel');
            $(this).removeClass('m2-manSealink-unsel');
            $(this).addClass('m2-manSealink-sel');
        });
        //加载更多按钮
        $('.m2-manageResult-more').click(function(){
            getRewordRecord();
        });
    });

    function getRewordRecord(){

        $.ajax({
            url:"usercenter-Rewardcontrol-getRewardLogAjax",
            type:"POST",
            data:{
                time1:time1,
                time2:time2,
                days:days,
                status:status,
                start:start
            },
            success:function(data){
                processData(data);
            }
        });
    }

    function processData(data){
        obj = eval('('+data+')');
        start++;
        pages = obj['pages'];
        checkBtn();
        showData(obj['data']);
    }

    function showData(obj){

        if(obj){
            var sum = Number($('#sum_reward').text());
            for(var i in obj){
                var tr = '<tr class="m2-manageResult-item">';
                tr += '<td>'+obj[i]['date']+'</td>';
                tr += '<td>'+obj[i]['type_text']+'</td>';
                tr += '<td title="'+obj[i]['info']+'">'+obj[i]['info']+'</td>';
                if(obj[i]['affect_money']>=0){
                    tr += '<td class="m2-manageResultitem-up">';
                }else{
                    tr += '<td class="m2-manageResultitem-down">';
                }
                tr += +obj[i]['affect_money']+'</td>';
                tr += '<td>'+obj[i]['reward_money']+'</td>';
                tr += '<td>'+(obj[i]['sum_inactive']?obj[i]['sum_inactive']:0)+'</td>';
                tr += '</tr>';
                $('.m2-manageResult-sum').before(tr);
                sum = calPlus(sum,obj[i]['affect_money']);
            }
            $('#sum_reward').text(sum);
            if(sum < 0){
                $('#sum_reward').css('color','#E64648');
            }else{
                $('#sum_reward').css('color','#717171');
            }
        }
        if($('.m2-manageResult-item').size() == 0){
            $('.m2-manageResult-sum').before('<tr class="m2-manageResult-item"><td colspan="6">暂无数据</td></tr>');
            $('.m2-manageResult-sum').hide();
        }
    }

    function getSearchData(){
        clear();
        days = 0;
        time1 = $('#m2-manSeadate-start').val();
        time2 = $('#m2-manSeadate-end').val();
        $('.m2-manageSearchsel-time span.m2-manSealink-sel').addClass('m2-manSealink-unsel');
        $('.m2-manageSearchsel-time span.m2-manSealink-sel').removeClass('m2-manSealink-sel');
        if(!time1 && !time2){
            $('.m2-manageSearchsel-time span').eq(0).addClass('m2-manSealink-sel');
        }
        var data = {
            time1:time1,
            time2:time2,
            days:days,
            status:status,
            start:start
        };
        return data;
    }

    function checkBtn(){
        if(start > pages){
            $('.m2-manageResult-more').hide();
        }
    }

    function clear(){
        start = 1;
        $('.m2-manageResult-item').remove();
        $('#sum_reward').text('0.00');
        $('#sum_reward').css('color','#717171');
        $('.m2-manageResult-more').show();
    }

    function calPlus(num1,num2){
        var sq1,sq2,m;
        try{sq1=num1.toString().split(".")[1].length;} catch(e){sq1=0;}
        try{sq2=num2.toString().split(".")[1].length;} catch(e){sq2=0;}
        m=Math.pow(10,Math.max(sq1,sq2));
        return Math.round(( num1 * m + num2 * m ) / m * 100)/100;
    }

    function ucDatepicker(locator,url,datafunc,callback){
        $(locator).datetimepicker({
            lang:'ch',
            timepicker:false,
            format:'Y-m-d',
            allowBlank:true,
            onChangeDateTime:function(){
                if(time1 != $('#m2-manSeadate-start').val() || time2 != $('#m2-manSeadate-end').val()){
                    $.ajax({
                        type: "POST",
                        url: url,
                        dataType: 'json',
                        data:datafunc(),
                        success: function(data) {
                            callback(data);
                        }
                    });
                }
            }
        });
    };
</script>
</body>
</html>